package com.kyxx.topics.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.kyxx.topics.R;
import com.kyxx.topics.view.MyCommonTitle;

import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler2;
import in.srain.cube.views.ptr.PtrFrameLayout;

/**
 * Created by Administrator on 2016/9/29.
 */
public class UserAddressManageActivity extends Activity implements View.OnClickListener, AdapterView.OnItemClickListener {
    private MyCommonTitle myCommonTitle;
    private ListView mListView;
    private PtrClassicFrameLayout ptrv;
    private TextView btnAddNew;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_address_manage);

        initView();
        initListener();
    }

    /**
     * 初始化控件
     */
    private void initView() {
        myCommonTitle = (MyCommonTitle) findViewById(R.id.aci_myTitle);
        myCommonTitle.setTitle("地址管理");
        myCommonTitle.setLisener(this,null);
        btnAddNew = (TextView) findViewById(R.id.aci_edit_btn);
        btnAddNew.setText("新增");
        mListView = (ListView) findViewById(R.id.listView);
        ptrv = (PtrClassicFrameLayout) findViewById(R.id.ptrv);

    }

    private void initListener() {
        btnAddNew.setOnClickListener(this);
        ptrv.setLastUpdateTimeFooterRelateObject(this);
        ptrv.setMode(PtrFrameLayout.Mode.REFRESH);
        ptrv.setPtrHandler(new PtrDefaultHandler2() {
            @Override
            public void onLoadMoreBegin(final PtrFrameLayout frame) {
                ptrv.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        frame.refreshComplete();
                    }
                }, 1000);
            }

            @Override
            public void onRefreshBegin(final PtrFrameLayout frame) {
                ptrv.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        frame.refreshComplete();
                    }
                }, 1000);
            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.aci_edit_btn:
                startActivity(new Intent(UserAddressManageActivity.this, UserAddNewAddress.class).putExtra("type", 1));
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        startActivity(new Intent(UserAddressManageActivity.this, UserAddNewAddress.class).putExtra("type", 2));
    }
}
